<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vue学习</title>
    <script src="./js/vue2.js"></script>
    <style>
      .title {
        color: red;
      }

      .font30 {
        font-size: 30px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <div :class="titleObj">我是一个标题</div>
      <button @click="addClassName">++++++++</button>
    </div>
    <script>
      new Vue({
        data: {
          titleObj: { title: true }
        },
        methods: {
          addClassName() {
            // this.titleObj.font30 = true
            // console.log(this.titleObj)

            // this.titleObj = { title: true, font30: true }
            // 深复制
            // this.titleObj = { ...this.titleObj, font30: true }
            // this.titleObj = Object.assign({}, this.titleObj, { font30: true })

            // vue2中一定要知道此方法用来新增对象的属性 this.$set
            this.$set(this.titleObj, 'font30', true)
          }
        }
      }).$mount('#app')
    </script>
  </body>
</html>
